home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-21 | 5.9 KB | 223 lines | [TEXT/PJMM] |
- {I needed to implement a spreasheet-style interface, in which two panes were enclosed in a single}
- {window. One of the two panes scrolled horizontally and vertically; the other pane scrolled only}
- {horizontally, and was fixed vertically.}
- {}
- {There's no documentation or examples on how to do this in the Think 3.0 package. I put roughly }
- {20 hours into making it work. In order to assist othersin the same circumstance, I am putting these }
- {docs up on CIS. Feel free to distribute them anywhere and to anyone.}
- {}
- {Key #1 is to make sure both panes are enclosed in the scroll pane. Otherwise the pane that isn't will}
- {draw itself on top of your scroll bars.}
- {}
- {Key #2 is to make both panes sized sizELASTIC, both horizontally and vertically, even though one of}
- {them is to be fixed at the top of the window. If you don't then once again that pane will draw itself}
- {on top of your scroll bars.}
- {}
- {Key #3 is to only attach one of the two panes to the scroll pane with InstallPanorama, namely, the}
- {pane that is to scroll in both directions. Otherwise you won't be able to get your scroll bars to}
- {activate.}
- {}
- {Key #4 is to make a subclass of cScrollPane and to install your panes in it (see above) rather than}
- {in a normal scrollpane. Then you override the DoThumbDrag and DoHorizScroll procedures, adding}
- {code that scrolls the second pane.}
-
- {Examples are enclosed below. I have also enclosed a screen dump that illustrates the final working}
- {window. I hope this saves you all the work it saved me!}
-
- {Vik Rubenfeld}
- {9/21/90}
-
-
-
- {INTERFACE FILE}
-
- CQuesDataDoc = object(CDocument)
-
- { Declare your document's instance variables here }
- RecursionLevel: Integer;
- ThisQuestion, HeadQuestion, FootQuestion: HandleToQuestion;
- ThisAnswerLabel: HandleToAnswerLabel;
- ThisQText: HandleToQText;
-
- DisplayMode: QuestionnaireDisplayModes;
- itsDialog: DialogPtr;
-
- itsSourceFile: cSourceFile;
- itsTargetFile: cTargetFile;
-
- itsQuesDataPane: CQuesDataPane;
- itsHeader: cPicture;
- itsScrollPane: cQuesDataScrollPane;
-
- { CQuesDataDoc's methods follow: }
- end;
-
- cQuesDataScrollPane = object(cScrollPane)
- procedure DoHorizScroll (whichPart: integer);
- override;
-
- procedure DoVertScroll (whichPart: integer);
- override;
-
- procedure DoThumbDrag (hDelta: integer;
- vDelta: integer);
- override;
- end;
-
-
- {DOCUMENT FILE}
- procedure CQuesDataDoc.BuildWindow (theData: Handle);
- var
- theWindow: cWindow;
- theScrollPane: cQuesDataScrollPane;
- thePanorama: cPanorama;
- theMainPane: cPane;
- theQuesDataPane: cQuesDataPane;
- theHeader: cPicture;
- begin
- new(theWindow);
- itsWindow := theWindow;
- itsWindow.IWindow(WINDQuesData, TRUE, gDesktop, SELF);
-
- new(theScrollPane);
- itsScrollPane := theScrollPane;
- itsScrollPane.IScrollPane(itsWindow, SELF, 10, 10, 0, 0, sizELASTIC, sizELASTIC, TRUE, TRUE, TRUE);
- itsScrollPane.FitToEnclFrame(TRUE, TRUE);
- itsScrollPane.SetWantsClicks(true);
-
- new(theQuesDataPane);
- itsQuesDataPane := theQuesDataPane;
- itsQuesDataPane.IQuesDataPane(itsScrollPane, SELF, 0, 0, 0, 0, sizELASTIC, sizELASTIC);
- itsQuesDataPane.FitToEnclosure(TRUE, TRUE);
- itsQuesDataPane.SetWantsClicks(true);
-
- new(theHeader);
- itsHeader := theHeader;
- itsHeader.IPicture(itsScrollPane, SELF, 0, 15, 0, 0, sizELASTIC, sizFIXEDTOP);
- itsHeader.FitToEnclosure(true, false);
- GetLineHeight(LineHeight, Monaco, 9);
- itsHeader.SetScales(LineHeight, LineHeight);
- itsHeader.SetWantsClicks(false);
-
- itsScrollPane.InstallPanorama(theQuesDataPane);
-
- itsMainPane := itsQuesDataPane;
- itsGopher := itsQuesDataPane;
- gGopher := itsQuesDataPane; {DON'T FORGET ABOUT gGOPHER}
- end;
-
- procedure cQuesDataDoc.SetBoundsForQuestionData;
- var
- LineHeight: Integer;
- RectForSetBounds: Rect;
- I: Integer;
- itsHeader: cPane;
- theRect: Rect;
-
- begin
- GetLineHeight(LineHeight, Monaco, 9);
- itsQuesDataPane.GetBounds(RectForSetBounds);
-
- S := ThisQuestion^^.NumberOfRows; {NumberOfRows is specific to my app. Replace it with a}
- {variable that contains the number of lines of text in your document}
-
- I := Num2Integer(Str2Num(S));
- RectForSetBounds.Bottom := I;
- RectForSetBounds.Right := 475 div LineHeight; {You might want to replace 475 with a global}
- {constant.}
-
- end;
-
- itsQuesDataPane.SetBounds(RectForSetBounds);
- end;
-
-
- procedure CQuesDataDoc.SetDisplayMode (RequestedMode: QuestionnaireDisplayModes);
- var
- theRect: Rect;
-
- begin
- if DisplayMode <> RequestedMode then
- begin
- DisplayMode := RequestedMode;
-
- SetBoundsForQuestionData;
-
- SetRect(theRect, 0, 16, 0, 0);
-
- itsQuesDataPane.ChangeSize(theRect, true);
-
- itsHeader.UsePict(3010);
- itsHeader.Draw(theRect);
- end;
- end;
-
- {THE SUBCLASS OF CSCROLLPANE}
- unit cQuesDataScrollPane;
-
- interface
-
- uses
- TCL, SANE, QuesDataIntf, cBufferedFile;
-
- implementation
- procedure cQuesDataScrollPane.DoHorizScroll (whichPart: integer);
- var
- delta, { Number of pixels to scroll }
- oldValue, { Current scroll bar setting }
- minmax: integer; { Minimum or Maximum delta }
- ticks: longint; { Tick count at end of Delay }
- begin
- case whichPart of
-
- inUpButton:
- delta := -hStep;
-
- inDownButton:
- delta := hStep;
-
- inPageUp:
- begin
- delta := hOverlap - hSpan;
- end;
-
- inPageDown:
- begin
- delta := hSpan - hOverlap;
- end;
- end;
-
- oldValue := itsHorizSBar.GetValue;
- if delta < 0 then
- begin
- minmax := itsHorizSBar.GetMinValue - oldValue;
- if delta < minmax then
- delta := minmax;
-
- end
- else
- begin
- minmax := itsHorizSBar.GetMaxValue - oldValue;
- if delta > minmax then
- delta := minmax;
- end;
-
- if delta <> 0 then
- gQuesDataDoc.itsHeader.Scroll(delta, 0, TRUE);
-
- inherited DoHorizScroll(whichPart);
- end;
-
- procedure cQuesDataScrollPane.DoVertScroll (whichPart: integer);
- begin
- inherited DoVertScroll(whichPart);
- end;
-
- procedure cQuesDataScrollPane.DoThumbDrag (hDelta: integer;
- vDelta: integer);
- begin
- if hDelta <> 0 then
- gQuesDataDoc.itsHeader.Scroll(hDelta, 0, TRUE);
- inherited DoThumbDrag(hDelta, vDelta);
- end;
- end.